/****** Object: View [dbo].[vw_4_1_2]   Script Date: 2014-01-19 21:45:28 ******/
USE [SHMIS];
GO
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vw_4_1_2]'))
BEGIN
DROP VIEW [dbo].[vw_4_1_2];
END
GO

SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE VIEW [dbo].[vw_4_1_2]
AS
   SELECT SUBSTRING (cast (ar.Date AS VARCHAR (10)), 1, 4) AS year,
          ar.Date,
          ar.Duration_Begin + '~' + ar.Duration_End AS duration,
          '' AS totaldays,
          CASE Amount_Type WHEN '01' THEN Amount ELSE 0 END AS house,
          CASE Amount_Type WHEN '02' THEN Amount ELSE 0 END AS equipment,
          CASE Amount_Type WHEN '03' THEN Amount ELSE 0 END AS properties,
          CASE Amount_Type WHEN '11' THEN Amount ELSE 0 END AS ent_park_fee,
          '' AS need_notice,
          ar.Customer_Code,
          ar.Contract_Num
     FROM HD_AccountReceivable ar, BI_ContractMain cm
    WHERE     ar.Customer_Code = cm.Customer_Code
          AND ar.Contract_Num = cm.Contract_Num
          AND ar.verified = '1'
          AND ar.deleted = '0'
          AND ar.audited = '1'
          AND cm.Verified = '1'
          AND cm.Deleted = '0'
          AND ISNULL (ar.adjust_serial_num, '') <> ''
GO

